package com.cool.controller.storecontroller;

import com.cool.common.Result;
import com.cool.po.storepo.StorePo;
import com.cool.service.store.StoreService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 仓库管理的控制层
 * 负责人:曹力引
 */
@RestController
public class StoreController {
    //查询状态的信息
    @Autowired
    private StoreService storeService;
    @RequestMapping("getState")
    Result getStates(){
        List<Integer> list = storeService.getState();
        return new Result("200","success",null,list);
    }
    //根据条件模糊查询所有信息
    @RequestMapping("getInfo")
    Result getInfo(Integer state,String like,Integer pagenumber,Integer pagesize){
        Map<String, Object> map=new HashMap<>();
        map.put("state",state);
        map.put("like",like);
        map.put("pagenumber",pagenumber);
        map.put("pagesize",pagesize);
        PageInfo<Map<String, Object>> list = storeService.getInfo(map);
        return new Result("200","success",list,null);
    }
    //批量删除
    @RequestMapping("deleteAll")
    Result deleteAll(String str){
        System.out.println(str);
        String[] strs = str.split(",");
        List<String> list = Arrays.asList(strs);
        storeService.deleteAll(list);
        return new Result("200","success",null,null);
    }
    //修改的方法
    @RequestMapping("updateAll")
    Result updateAll(String ck_id,String ck_name,String ck_people,String ck_tel,String ck_md,String ck_state){
        System.out.println(ck_id+","+ck_name+","+ck_people+","+ck_tel+","+ck_md+","+ck_state);
        Map<String, Object> map=new HashMap<>();
        map.put("ck_id",ck_id);
        map.put("ck_name",ck_name);
        map.put("ck_people",ck_people);
        map.put("ck_tel",ck_tel);
        map.put("ck_md",ck_md);
        map.put("ck_state",ck_state);
        storeService.updateAll(map);
       return new Result("200","success",null,null);
    }
}
